import requests
from common.token_data import TokenTool
from common.inquire_department_id import inquire_department

"""
部门添加接口
"""


class ApiDepartMent(object):
    # 查询全部部门数据
    @classmethod
    def inquire_department(cls, token_login):
        resp = requests.get("https://heimahr.itheima.net/api/company/department", headers=token_login)
        return resp

    # 添加部门
    @classmethod
    def add_department(cls, token_login, department_data):
        resp = requests.post("https://heimahr.itheima.net/api/company/department", headers=token_login,
                             json=department_data)
        return resp

    # 删除部门
    @classmethod
    def delete_department(cls, department_id, token_login):
        resp_delete = requests.delete(f"https://heimahr.itheima.net/api/company/department/{department_id}",
                                      headers=token_login)
        return resp_delete

    # 修改部门
    @classmethod
    def put_department(cls, department_id, token_login, revise_data):
        resp_revise = requests.put(f"https://heimahr.itheima.net/api/company/department/{department_id}",
                                   headers=token_login, json=revise_data)
        return resp_revise


if __name__ == '__main__':
    # 全为必选参数
    department_data = {"code": "111", "introduce": "第一次尝试", "managerId": 19, "name": "寻找部门ID", "pid": 1}
    resp_department = ApiDepartMent.add_department(TokenTool.token_data(), department_data)
    print("部门添加结果：", resp_department.json())
    # resp_inquire = ApiDepartMent.inquire_department(token_data, "寻找部门ID")
    # print(resp_inquire)
    put_department_data = {"id": 19, "pid": 1, "name": "测试修改", "code": "111", "managerId": 19,
                           "managerName": "黑马测试", "introduce": "修改查询"}
    resp_put = ApiDepartMent.put_department(inquire_department(f"{department_data["name"]}"), TokenTool.token_data(),
                                            put_department_data)
    print("部门修改得结果",resp_put.json())

    resp_inquire = ApiDepartMent.inquire_department(TokenTool.token_data())
    print("部门查询得结果",resp_inquire.json())

    resp_delete = ApiDepartMent.delete_department(inquire_department(f"{put_department_data["name"]}"),TokenTool.token_data())
    print("部门删除得结果",resp_delete.json())